Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(node): Extract Sentry-specific node-fetch instrumentation #15231

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from

Conversation

mydea
Copy link
Member

@mydea mydea commented Jan 30, 2025

This PR basically mirrors what we did here: #13763

to ensure that the UndiciInstrumentation from fetch can be safely removed.

With this change, if spans: false is configured and/or skipOpenTelemetrySetup: true, no core otel instrumentations will be added anymore at all. This should also make it easier when in a follow up step we make this completely optional, allowing us to drop all instrumentation dependencies for these cases.

While doing this I noticed that we should probably also adjust our custom http instrumentation to inject sentry-trace as well, to fully decouple this. I'll check this out separately...

Closes #15212

Possible extension in the future: Also capture fetch request bodies. (We already do not do this today, but may add this at some point...)

@mydea mydea requested review from lforst and Lms24 January 30, 2025 09:31
@mydea mydea self-assigned this Jan 30, 2025
@mydea mydea force-pushed the fn/node-fetch-custom branch from 3ab670c to 4c6e295 Compare January 30, 2025 09:34
Copy link
Contributor

github-actions bot commented Jan 30, 2025

size-limit report 📦

Path Size % Change Change
@sentry/browser 23.03 KB - -
@sentry/browser - with treeshaking flags 22.92 KB - -
@sentry/browser (incl. Tracing) 35.8 KB - -
@sentry/browser (incl. Tracing, Replay) 72.59 KB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 66.13 KB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 76.85 KB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 89.35 KB - -
@sentry/browser (incl. Feedback) 39.71 KB - -
@sentry/browser (incl. sendFeedback) 27.66 KB - -
@sentry/browser (incl. FeedbackAsync) 32.44 KB - -
@sentry/react 24.84 KB - -
@sentry/react (incl. Tracing) 37.69 KB - -
@sentry/vue 27.14 KB - -
@sentry/vue (incl. Tracing) 37.52 KB - -
@sentry/svelte 23.15 KB - -
CDN Bundle 24.23 KB - -
CDN Bundle (incl. Tracing) 35.91 KB - -
CDN Bundle (incl. Tracing, Replay) 70.56 KB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 75.69 KB - -
CDN Bundle - uncompressed 70.83 KB - -
CDN Bundle (incl. Tracing) - uncompressed 106.57 KB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 217.42 KB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 229.99 KB - -
@sentry/nextjs (client) 38.65 KB - -
@sentry/sveltekit (client) 36.3 KB - -
@sentry/node 157.02 KB +0.32% +508 B 🔺
@sentry/node - without tracing 98.09 KB +0.47% +460 B 🔺
@sentry/aws-serverless 107.5 KB +0.4% +428 B 🔺

View base workflow run

Comment on lines 133 to 175
if (Array.isArray(request.headers)) {
const requestHeaders = request.headers;
Object.entries(addedHeaders)
.filter(([k]) => {
// If the header already exists, we do not want to set it again
return !requestHeaders.includes(k);
})
.forEach(keyValuePair => requestHeaders.push(...keyValuePair));
} else {
const requestHeaders = request.headers;
request.headers += Object.entries(addedHeaders)
.filter(([k]) => {
// If the header already exists, we do not want to set it again
return !requestHeaders.includes(`${k}:`);
})
.map(([k, v]) => `${k}: ${v}\r\n`)
.join('');
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m: same concern about the baggage header as in #15233 (comment)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I'll pull this in from the other PR after merging that!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated it!

mydea added a commit that referenced this pull request Jan 31, 2025
Related to #15231, I
noticed that we today would not propagate traces in outgoing http
requests if:

1. The user configures `httpIntegration({ spans: false })`
2. ..._or_ the user has a custom OTEL setup
3. _and_ the user does not add their own `HttpInstrumentation`

Admittedly and edge case. More importantly, though, by actually adding
distributed tracing information here, we are unblocked from potentially
stopping to ship the http-instrumentation to users that do not need
spans (and/or have a custom otel setup).

---------

Co-authored-by: Lukas Stracke <[email protected]>
@mydea mydea force-pushed the fn/node-fetch-custom branch from 653a5d8 to 07e8184 Compare January 31, 2025 10:21
@mydea mydea requested a review from Lms24 February 3, 2025 11:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Extract node-fetch non-span functionality into standalone instrumentation
2 participants